/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package usuario.control;

import bibliinfo.FrameMain;
import java.util.List;
import javax.swing.JOptionPane;
import usuario.model.Usuario;
import usuario.model.UsuarioDao;

/**
 *
 * @author Ar0n
 */
public class UserFameDadosEdit extends javax.swing.JInternalFrame {

    /**
     * Creates new form UserFameDadosEdit
     */
    public UserFameDadosEdit() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jBEdit = new javax.swing.JButton();
        jBAdd = new javax.swing.JButton();
        jBFechar = new javax.swing.JButton();

        addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
                formAncestorAdded(evt);
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
            }
        });

        jBEdit.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBEdit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/img_user/1365466392_notepad_(edit)_16x16.gif"))); // NOI18N
        jBEdit.setText("Editar");
        jBEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBEditActionPerformed(evt);
            }
        });

        jBAdd.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/img_user/1365839912_netvibes.png"))); // NOI18N
        jBAdd.setText("Dados Adicionais");
        jBAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAddActionPerformed(evt);
            }
        });

        jBFechar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBFechar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/img_user/1365683699_window-close.png"))); // NOI18N
        jBFechar.setText("Fechar");
        jBFechar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBFecharActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(jBFechar, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 385, Short.MAX_VALUE)
                .addComponent(jBEdit, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(35, 35, 35))
            .addGroup(layout.createSequentialGroup()
                .addGap(320, 320, 320)
                .addComponent(jBAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBEdit, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBFechar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(31, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAddActionPerformed

        FrameMain.userFrameDados.setVisible(false);
        FrameMain.userFrameDados.setEstado(false);

        FrameMain.userFrameAdd.setVisible(true);
        FrameMain.userFrameAdd.setEstado(true);  
        FrameMain.mapa.put("frame13", FrameMain.userFrameAdd);
        FrameMain.formata(13);        
        
        FrameMain.userFrameAdd.setComponente(1);  
        FrameMain.userFrameAdd.chamarAdd();
        FrameMain.formata(13);
        FrameMain.userFrameAdd.setComponente(1);  
    }//GEN-LAST:event_jBAddActionPerformed

    private void jBFecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBFecharActionPerformed
        FrameMain.userFrameDados.setVisible(false);
        FrameMain.userFrameDados.setEstado(false);
        
        FrameMain.userFrameMain.setVisible(true);
        FrameMain.userFrameMain.setEstado(true);
        FrameMain.formata(11);  
    }//GEN-LAST:event_jBFecharActionPerformed

    private void jBEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBEditActionPerformed
    /**
     Esta parte do código impedir que o funcionario consiga editar os dados de um usuário deletado
     * e este método, ainda habilita o botão restaurar
     */    
        String rg = String.valueOf(FrameMain.userFrameDados.getRgAntigo());
        UsuarioDao dao = new UsuarioDao();
        List<Usuario> lista = dao.read(rg, 2);
        Usuario user = lista.get(0);        
        if(user.getAtivo() == false){
            JOptionPane.showMessageDialog(FrameMain.userFrameDados, "<html>O usuário foi deletado do sistema.<br />Para editar os seus dados ele deve ser <b color=\"blue\">restaurado</b></html>", "Bloqueio", 2);            
        }else{
            FrameMain.userFrameDados.habilitaCampos();
            FrameMain.userFrameDados.escolheComp("update");
            if(FrameMain.userFrameAdd.jRBSim.isSelected() == true){
                FrameMain.userFrameAdd.habitaData(true);
            }
        }      
    }//GEN-LAST:event_jBEditActionPerformed

    private void formAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_formAncestorAdded
        //FrameMain.formata(13);
        FrameMain.formata(12);
        FrameMain.userFrameAdd.jBrestaurar.jBRestaurar.setEnabled(true);
    }//GEN-LAST:event_formAncestorAdded

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBAdd;
    private javax.swing.JButton jBEdit;
    private javax.swing.JButton jBFechar;
    // End of variables declaration//GEN-END:variables
      
}
